package homewoek12月12号.homework2.h4;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class demo {
    public static void main(String[] args) throws Exception {
        System.out.println("【查询手机】");
        System.out.println("【黑色】");
        System.out.println("【白色】");
        System.out.println("【银色】");
        System.out.println("【金色】");
        System.out.println("【退出】");
        String s = new Scanner(System.in).nextLine();
        SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ldea dashuju\\day.12.11\\src\\czxy\\homework\\h4\\phone.xml");
        Element root = read.getRootElement();
        List<Element> phone = root.elements();
        ArrayList<phone> slist = new ArrayList<>();
        for (Element element : phone) {
           slist.add(new phone(element.elementText("name"),element.elementText("brand"),
                   Double.parseDouble(element.elementText("size")),
                   Integer.parseInt(element.elementText("price")),element.elementText("color")));
        }
        for (czxy.homework.h4.phone p : slist) {
            if (p.color.equals(s)){
                System.out.println(p.name+" "+p.brand+" "+p.size+" "+p.price+" "+p.color);
                return;
            }if (s.equals("退出")){
                System.out.println("退出成功！！！");
                return;
            }
        }
        System.out.println("没有你想要的颜色！！！");
    }
}
